const router = require('koa-router')()
const {getComment,getCommentById,postComment,patchComment,deleteComment}=require('../../controller/comment')

router.prefix('/api/comment')

router.get('/comment', async (ctx, next) => {
  const {pageIndex = 0, pageSize = 10} = ctx.query
  ctx.body = await getComment({pageIndex, pageSize})
})

router.get('/comment/:id', async (ctx, next) => {
  const {id} = ctx.params
  ctx.body = await getCommentById(id)
})

router.post('/comment', async (ctx, next) => {
  const {title, content, imgs, houseId} = ctx.request.body
  ctx.body = await postComment(ctx, {title, content, imgs, houseId})
})

router.patch('/comment', async (ctx, next) => {
  const {title, content, imgs, id} = ctx.request.body
  ctx.body = await patchComment({title, content, imgs, id})
})

router.delete('/comment/:id', async (ctx, next) => {
  const {id} = ctx.params
  ctx.body = await deleteComment(id)
})

module.exports = router
